<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="author" content="mengxiangzhong">
	<title>卡充值</title>
	<script language="javascript" src="/script/common.js" type="text/javascript"></script>
	<script language="javascript" src="/script/card.js" type="text/javascript"></script>
	<script language="javascript" type="text/javascript">
		var pos = {
		}
	
		var card = {
			expiredTime : "20081101"
		}
		var data = {};
		var backData={};
		var pswd = "111111"
		var operUniqueId = Common.cOperator().uniqueId
		var operId = Common.cOperator().id
		var cardType = "00";
		//初始化页面信息
		function load(){
			showNav();
			Common.initDict($("currency"),"currency")
			if (false && Project && Project.asnLength!=12){
				$("zhgj").style.display = "none";
				$("petro").style.display = "";
			}
	 	}
	 	
	 	function showData(){
	 		var html = "";
	 		html += "pos 流水号 "+pos.sn +"<br>"
	 		html += "result data:<br>"
	 		for(prop in data){
	 			if (typeof data[prop] == "function")continue;
	 			html += prop + ":"+data[prop]+"<br>"
	 		}
	 		$("dataview").innerHTML = html;
	 	}
	 	
	 	function testSellCard(){
	 		var asn = $("asn").value
			DWR.call("pospService.sellCard",pos.uniqueId,operId,asn,getCardData(),function(v){
				data = v
				alert("pospService.sellCard ok")
				showData();
			});
	 	}
	 	function testDeposit(){
	 		var amount = $("amount").value
	 		var asn = $("asn").value
	 		pos.sn ++
	 		DWR.call("zhgjService.testGetBalance",asn,function(balance){
	 			$("balanceview").innerHTML = "余额1："+balance
				DWR.call("pospService.deposit",pos.uniqueId,operId,pos.sn,asn,yuanToFen(amount),getCardData(),balance,function(v){
					data=v;
					alert("pospService.deposit ok")
					getBalance();
					showData();
				});
			});
	 	}
	 	function testExchangeRate(){
	 		var er = {
	 			rate:$("exchangeRate").value * 10000,
	 			currency:Currency.PATACA
	 		}
	 		DWR.call("exchangeRateService.saveExchangeRate",er,function(v){
	 			alert("exchangeRateService.saveExchangeRate ok")
	 			DWR.call('exchangeRateService.startExchangeRate',v.id,function(r){
					showQuestion("汇率启用成功!")
				});
	 		});
	 	}
	 	//签到
	 	function signIn(){
	 		DWR.call("pospService.signIn",pos.uniqueId,operUniqueId,$("operpassword").value,function(r){
	 			operId = r.operId
	 			alert("pospService.signIn ok")
	 			showData()
	 		})
	 	} 
	 	function testLogin(){
	 		pos.uniqueId = $("posUniqueId").value
	 		DWR.call("pospService.login",pos.uniqueId,function(r){
	 			pos.uniqueId = r.posNo
	 			pos.sn = r.tradeId
	 			alert("pospService.login ok")
	 		})
	 	}
	 	//签到
	 	function signOut(){
	 		DWR.call("pospService.signOut",pos.uniqueId,operId,function(){
	 			alert("ospService.signOut ok")
	 		})
	 	} 
	 	function changePassword(){
	 		DWR.call("pospService.modifyPassword",pos.uniqueId,operId,$("newpassword").value,$("oldpassword").value,function(){
	 			alert("pospService.modifyPassword ok")
	 		})
	 	}
	 	function posUnLock(){
	 		DWR.call("pospService.posUnLock",pos.uniqueId,operId,$("posUnLockPassword").value,function(){
	 			alert("pospService.modifyPassword ok")
	 		})
	 	}
	 	
	 	function testCancelTrade(){
	 		var amount = $("amount").value
	 		var asn = $("asn").value
	 		var tradeId = $("tradeId").value
	 		pos.sn ++
	 		DWR.call("zhgjService.testGetBalance",asn,function(balance){
	 			$("balanceview").innerHTML = "余额1："+balance
		 		DWR.call("pospService.cancelCardDeposit",pos.uniqueId,operId,pos.sn,asn,amount*100,balance,tradeId,function(){
		 			alert("pospService.cancelCardDeposit ok")
		 			DWR.call("pospService.confirmUnload",pos.uniqueId,operId,pos.sn,function(){
			 			getBalance()
						showData();
		 			});
		 		})
	 		})
	 	}
	 	function getBalance(v){
	 		var asn = $("asn").value
	 		DWR.call("zhgjService.testGetBalance",asn,function(balance){
	 			$("balanceview").innerHTML += "余额2"+(v?v:"")+"："+balance
	 		})
	 	}
	 	function reversal(){
	 		var amount = $("reversalAmount").value
	 		var asn = $("asn").value
	 		pos.sn ++
	 		DWR.call("zhgjService.testGetBalance",asn,function(balance){
	 			$("balanceview").innerHTML = "余额1："+balance
				DWR.call("pospService.deposit",pos.uniqueId,operId,pos.sn,asn,yuanToFen(amount),'1020020101Y',balance,function(v){
					data=v;
					alert("pospService.deposit ok")
					getBalance();
					showData();
					DWR.call("pospService.rollbackLoad",pos.uniqueId,operId,pos.sn,function(v){
						alert("pospService.rollbackLoad ok")
						getBalance("reversal");
					})
				});
			});
	 	}
	 	
	 	function annualAudit(){
	 		DWR.call("pospService.annualAudit",pos.uniqueId,operId,$("asn").value,getCardData(),function(v){
	 			card.expiredTime = v.expiredTime
	 			alert("pospService.annualAudit ok " + v.expiredTime)
	 		})
	 	}
	 	
	 	function retCard(){
	 		var asn = $("asn").value
	 		pos.sn ++
	 		DWR.call("zhgjService.testGetBalance",asn,function(balance){
		 		DWR.call("pospService.cashWithdraw",pos.uniqueId,operId,pos.sn,asn,balance,balance,getCardData(),function(v){
		 			alert("pospService.cashWithdraw ok "+v.msg)
		 			DWR.call("pospService.retCard",pos.uniqueId,operId,pos.sn,asn,function(v){
		 				alert("pospService.retCard ok " + Common.getText("card_status",v.status))
		 			});
		 		})
	 		})
	 	}
	 	function getCardData(){
	 		var currency;
	 		if ($("currency").value == Currency.RMB)
	 			currency = "Y"
	 		else if ($("currency").value == Currency.PATACA)
	 			currency = "N"
	 		else{
	 			showError("不支持的币种!");return;
	 		}
	 		return getZhgjCardType() + card.expiredTime+ currency +"9010"
	 	}
	 	function getZhgjCardType(){
	 		if ($("zhgjcardtype").value)
	 			return $("zhgjcardtype").value;
	 		else
	 			return "00";
	 	}
	 	function checkBlackCard(){
	 		var asn = $("asn").value
	 		DWR.call("zhgjService.checkBlackCard",asn,function(){
		 		alert("zhgjService.checkBlackCard ok ")
	 		})
	 		
	 	}
	 	
	 	function settle(){
	 		DWR.call("pospService.settle",pos.uniqueId,operId,function(r){
		 		alert("pospService.settle ok:\n" + r.msg)
	 		})
	 	}
	 	function collectTx(){
	 		DWR.call("pospService.collectTx",pos.uniqueId,operId,function(r){
		 		alert("pospService.collectTx ok:\n" + r.msg)
	 		})
	 	}
	 	function transferTx(){
	 		DWR.call("zhgjService.transferTx",function(){
		 		alert("zhgjService.transferTx ok ")
	 		})
	 	}
	 	function transferMgnt(){
	 		DWR.call("zhgjService.transferMgnt",function(){
		 		alert("zhgjService.transferMgnt ok ")
	 		})
	 	}
	 	function autoTransfer(){
	 		DWR.call("zhgjService.autoTransfer",function(){
		 		alert("zhgjService.autoTransfer ok ")
	 		})
	 	}
	 	
	 	function connectHSPos(){
	 		DWR.call("pospService.getSectorKey",pos.uniqueId,"1111",function(){
		 		alert("pospService.getSectorKey ok ")
	 		})
	 	}
	 	
	 	var cardTypeId;
	 	function selCardType(){	
			var v = openDialogFrame("/basic/card_type_list.html?",'请选择卡片类型',464,700)
			if (v){
				cardTypeId=v[0];
				$("cardType").value = v[1];
			}
	 	}
	 	function cardin(){
	 		var asn = $("petroasn").value
	 		DWR.call("reportService.testAddCard",asn,cardTypeId,function(){
	 			alert("ok")
	 		})
	 	}
	 	function readCard(){
	 		getCard();
	 		$("petroasn").value = getAsn();
	 	}
	</script>
</head>
<body onload="load()" onunload="releaseCard()">
	<!--页面导航-->
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<div id="petro">
	<table border=1 class="label4">
	<tr>
	<td><label>卡号</label></td><td><input type="text" id="petroasn"></td>
	<td>
		<button onclick="readCard()">读卡</button></td>
	</tr>
	<tr>
	<td><label>卡类型</label></td><td>
	<input type="text" id="cardType" readonly class="readonly" onblur="checkV(this,'',true)" >
	<a class="orga" title="请选择卡片类型" href="javascript:void(0)" onclick="selCardType()">&nbsp;&nbsp;</a>
	</td>
	<td>
		<button onclick="cardin()">入库</button></td>
	</tr>
	</table>
		
	</div>
	<div  id='zhgj'>
	<table border=1>
	<tr>
	<td>支付币种</td><td><select name=currency></select></td><td>&nbsp;</td>
	</tr>
	<tr>
	<td>终端编号</td><td><input type=text id=posUniqueId value="12345678"></td><td><button onclick="testLogin()">终端开机</button>
	</td>
	</tr>
	<tr>
	<td>密码</td><td><input type=text id=operpassword value="111111"></td><td><button onclick="signIn()">签到</button></td>
	</tr>
	<tr>
	<td>签退</td><td>&nbsp;</td><td><button onclick="signOut()">签退</button></td>
	</tr>
	<tr>
	<td>密码</td><td><input type=text id=posUnLockPassword></td><td><button onclick="posUnLock()">终端解锁</button></td>
	</tr>
	<tr>
	<td>旧密码</td>
	<td><input type=text id=oldpassword><br>
		<input type=text id=newpassword>
		</td><td>
		<button onclick="changePassword()">修改密码</button></td>
	</tr>
	<tr>
	</tr>
	<tr>
	<td>
	增加汇率</td><td><input type=text id="exchangeRate" value=150></td><td>
		<button onclick="testExchangeRate()">增加启用汇率</button></td>
	</tr>
	<tr>
	<td><span style="color:red">卡类型</span></td><td>
		<input type="text" value="00" id="zhgjcardtype"></td>
		<td>&nbsp;</td>
	</tr>
	<tr>
	<td><span style="color:red">卡号</span></td><td>
		<input type="text" value="100000000000" id="asn"></td>
		<td><button onclick="testSellCard()">发卡</button></td>
	</tr>
	<tr>
	<td>充值</td><td>
		<input type="text" value="100" id="amount"></td><td>
		<button onclick="testDeposit()">充值</button>
	</td>
	</tr>
	<tr>
	<td>充值冲正</td><td>
		<input type="text" value="100" id="reversalAmount"></td><td>
		<button onclick="reversal()">充值冲正</button></td>
	</tr>
	<tr>
	<td>交易流水号</td><td>
		<input type="text" id="tradeId"></td><td>
		<button onclick="testCancelTrade()">充值撤销</button></td>
	</tr>
	<tr>
	<td>年审</td><td>&nbsp;</td><td>
		<button onclick="annualAudit()">年审</button>
	</td>
	</tr>
	<tr>
		<td>退卡</td><td>&nbsp;</td>
		<td><button onclick="retCard()">退卡</button></td>
	</tr>
	<tr>
	<td>是否黑名单</td><td>&nbsp;</td><td>
		<button onclick="checkBlackCard()">检验</button>
	</td>
	</tr>
	<tr>
	<td>对帐</td><td>&nbsp;</td><td>
		<button onclick="settle()">对帐</button>
	</td>
	</tr>
	<tr>
	<td>统计</td><td>&nbsp;</td><td>
		<button onclick="collectTx()">统计</button>
	</td>
	</tr>
	<tr>
	<td>连安控POS</td><td>&nbsp;</td><td>
		<button onclick="connectHSPos()">CONNECT</button>
	</td>
	</tr>
	<tr><td colspan=3 align=center>
		<button onclick="transferTx()">TX</button>
		<button onclick="transferMgnt()">MGNT</button>
		<button onclick="autoTransfer()">test</button>
	</td>
	</tr>
	</table>
	
	
	<div id="dataview">
	</div>
	<div>
		卡余额：<div id="balanceview">
		</div>
	</div>
	</div>
</body>
</html>